package manager;

/**
 * @author huangjm.2012, huiwensong.2012, sheryl.tay.2012, mohameds.2012
 *
 */

import java.util.ArrayList;

import entity.Section;

public class SectionMgr {

	DatabaseMgr dbMgr;

	public SectionMgr() {
		dbMgr = new DatabaseMgr();
	}

	public void addSection(Section section) {

		String sql = "INSERT INTO section "
				+ " (courseCode, sectionCode, dayOfWeek, startTime, endTime,instructor, venue, size) "
				+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?) ";

		dbMgr.openAndUpdateAndClose(sql, section.getCourse().getCourseCode(),
				section.getSectionCode(), section.getDayOfWeek(),
				section.getStartTime(), section.getEndTime(),
				section.getInstructor(), section.getVenue(), section.getSize());
	}

	public ArrayList<Section> retrieveAllSections() {
		return RetrieveSectiontUtil.retrieveMultipleSectionsForQuery(dbMgr,
				"select * from section_course ");

	}

	public ArrayList<Section> retrieveSectionsForCourse(String courseCode) {

		String sql = "select * from section_course where courseCode=? ";

		return RetrieveSectiontUtil.retrieveMultipleSectionsForQuery(dbMgr,
				sql, courseCode);
	}

	public void deleteAllSections() {
		dbMgr.openAndUpdateAndClose("delete from section");
	}

}
